//
//  AutoreleasePool.cpp
//  Simulation
//
//  Created by Christopher Kemsley on 3/4/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//

#include "AutoreleasePool.hpp"
#include "RunLoop.hpp"

using namespace Sim;



AutoreleasePool :: AutoreleasePool ()
:	mPool()
	{
	
	}
AutoreleasePool :: ~AutoreleasePool ()
	{
	drain () ;
	}

void	AutoreleasePool :: drain ()
	{
	std::vector<Object*>::iterator	here	=	mPool.begin() ;
	std::vector<Object*>::iterator	end		=	mPool.end() ;
	while ( here < end )
		(*(here++)) -> release() ;
	mPool.clear() ;
	}

AutoreleasePool&	AutoreleasePool :: current ()
	{
	return RunLoop::currentLoop().currentPool() ;
	}

void	AutoreleasePool :: autorelease	( Object * inObject )
	{
	mPool . push_back ( inObject ) ;
	}

